package models

import (
	"os"

	"github.com/astaxie/beego"
)

type Item struct {
	Id          int    // 编号
	Name        string // 名称
	Price       int    // 倍率
	Probability int    // 中奖概率   例：  1% * 10000
	code        []int  // 中奖物品对应 中奖格子编号
}

func init() {

	items := getItems()

	sum := 0
	prices := make(map[int]int)
	var code [26]int
	for _, v := range items {
		sum += v.Probability
		prices[v.Price] = prices[v.Price] + 1
		for _, vv := range v.code {
			code[vv] = 1
		}
	}
	if sum != 10000 {
		beego.Error("中奖概率【错误】", sum)
		os.Exit(1)
	} else {
		beego.Info("中奖概率【正确】")
	}
	sum = 0
	for _, v := range code {
		if v == 1 {
			sum++
		}
	}
	beego.Info("中奖格子数量：", sum)
	beego.Info("中奖倍率:数量", prices)
}

func getItems() []Item {
	var items []Item
	id := 1
	items = append(items, Item{Id: id, Name: "苹果5", Price: 5, Probability: 565, code: []int{3, 8, 14, 19}})
	id++
	items = append(items, Item{Id: id, Name: "苹果3", Price: 3, Probability: 944, code: []int{4}})
	id++
	items = append(items, Item{Id: id, Name: "橙子10", Price: 10, Probability: 283, code: []int{10, 21}})
	id++
	items = append(items, Item{Id: id, Name: "橙子15", Price: 15, Probability: 188, code: []int{10, 21}})
	id++
	items = append(items, Item{Id: id, Name: "橙子20", Price: 20, Probability: 141, code: []int{10, 21}})
	id++
	items = append(items, Item{Id: id, Name: "橙子3", Price: 3, Probability: 942, code: []int{9}})
	id++
	items = append(items, Item{Id: id, Name: "木瓜10", Price: 10, Probability: 283, code: []int{5, 16}})
	id++
	items = append(items, Item{Id: id, Name: "木瓜15", Price: 15, Probability: 188, code: []int{5, 16}})
	id++
	items = append(items, Item{Id: id, Name: "木瓜20", Price: 20, Probability: 141, code: []int{5, 16}})
	id++
	items = append(items, Item{Id: id, Name: "木瓜3", Price: 3, Probability: 942, code: []int{15}})
	id++
	items = append(items, Item{Id: id, Name: "铃铛10", Price: 10, Probability: 283, code: []int{11, 22}})
	id++
	items = append(items, Item{Id: id, Name: "铃铛15", Price: 15, Probability: 188, code: []int{11, 22}})
	id++
	items = append(items, Item{Id: id, Name: "铃铛20", Price: 20, Probability: 141, code: []int{11, 22}})
	id++
	items = append(items, Item{Id: id, Name: "铃铛3", Price: 3, Probability: 942, code: []int{20}})
	id++
	items = append(items, Item{Id: id, Name: "西瓜20", Price: 20, Probability: 141, code: []int{6}})
	id++
	items = append(items, Item{Id: id, Name: "西瓜30", Price: 30, Probability: 94, code: []int{6}})
	id++
	items = append(items, Item{Id: id, Name: "西瓜40", Price: 40, Probability: 71, code: []int{6}})
	id++
	items = append(items, Item{Id: id, Name: "西瓜3", Price: 3, Probability: 942, code: []int{7}})
	id++
	items = append(items, Item{Id: id, Name: "双星20", Price: 20, Probability: 141, code: []int{17}})
	id++
	items = append(items, Item{Id: id, Name: "双星30", Price: 30, Probability: 94, code: []int{17}})
	id++
	items = append(items, Item{Id: id, Name: "双星40", Price: 40, Probability: 71, code: []int{17}})
	id++
	items = append(items, Item{Id: id, Name: "双星3", Price: 3, Probability: 942, code: []int{18}})
	id++
	items = append(items, Item{Id: id, Name: "双七20", Price: 20, Probability: 141, code: []int{12}})
	id++
	items = append(items, Item{Id: id, Name: "双七30", Price: 30, Probability: 94, code: []int{12}})
	id++
	items = append(items, Item{Id: id, Name: "双七40", Price: 40, Probability: 71, code: []int{12}})
	id++
	items = append(items, Item{Id: id, Name: "双七3", Price: 3, Probability: 942, code: []int{13}})
	id++
	items = append(items, Item{Id: id, Name: "BAR50", Price: 50, Probability: 57, code: []int{1}})
	id++
	items = append(items, Item{Id: id, Name: "BAR100", Price: 100, Probability: 28, code: []int{2}})
	return items
}

/*
mode:
	0	无
	1	红LUCK
	2	蓝LUCK
	3	BAR奖励
	4	小三元
	5	大三元
	6	大四喜奖励
	7	纵横四海
	8	随机奖励

中奖格子
wincode：
	1	BAR(50倍)
	2	BAR(100倍)
	3	大苹果(上排)
	4	小苹果(上排)
	5	大木瓜(右上角)
	6	大西瓜(右排)
	7	小西瓜(右排)
	8	大苹果(右排)
	9	小橙子(右排)
	10	大橙子(右下角)
	11	大铃铛(下排)
	12	小双七(下排)
	13	大双七(下排)
	14	大苹果(下排)
	15	小木瓜(下排)
	16	大木瓜(左下角)
	17	大双星(左排)
	18	小双星(左排)
	19	大苹果(左排)
	20	小铃铛(左排)
	21	大橙子(左上角)
	22	大铃铛(上排)
	23	红LUCK
	24	蓝LUCK
*/
